//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "DigitalCoupon.h"
using namespace Cephei::QL::Cashflows;
#include <gen/QL/Cashflows/FloatingRateCoupon.h>
#include <gen/QL/Cashflows/DigitalReplication.h>
#include <gen/QL/Cashflows/FloatingRateCouponPricer.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Indexes/InterestRateIndex.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Cashflows::CDigitalCoupon::CDigitalCoupon (Cephei::QL::Cashflows::IFloatingRateCoupon^ underlying, Microsoft::FSharp::Core::FSharpOption<Double>^ callStrike, Microsoft::FSharp::Core::FSharpOption<QL::Position::TypeEnum>^ callPosition, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isCallITMIncluded, Microsoft::FSharp::Core::FSharpOption<Double>^ callDigitalPayoff, Microsoft::FSharp::Core::FSharpOption<Double>^ putStrike, Microsoft::FSharp::Core::FSharpOption<QL::Position::TypeEnum>^ putPosition, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isPutITMIncluded, Microsoft::FSharp::Core::FSharpOption<Double>^ putDigitalPayoff, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Cashflows::IDigitalReplication^>^ replication, Cephei::QL::Cashflows::IFloatingRateCouponPricer^ QL_Pricer) : CFloatingRateCoupon(CDigitalCoupon::typeid)
{
    CFloatingRateCoupon^ _Cunderlying;
    CDigitalReplication^ _Creplication;
    try
    {
#ifdef HANDLE
        _phDigitalCoupon = NULL;
#endif
        _Cunderlying = safe_cast<CFloatingRateCoupon^> (underlying);
        _Cunderlying->Lock();
        boost::shared_ptr<QuantLib::FloatingRateCoupon>& _underlying = static_cast<boost::shared_ptr<QuantLib::FloatingRateCoupon>&> (_Cunderlying->GetShared ()); 
        QuantLib::Rate _callStrike = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (callStrike) ? (QuantLib::Rate)ValueHelper::Convert (callStrike->Value) : Null<QuantLib::Rate>()); //4
        QuantLib::Position::Type _callPosition = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Position::TypeEnum>::IsSome::get (callPosition) ? (QuantLib::Position::Type)callPosition->Value : QuantLib::Position::Type::Long); //10
        bool _isCallITMIncluded = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isCallITMIncluded) ? (bool)ValueHelper::Convert (isCallITMIncluded->Value) : false); //4
        QuantLib::Rate _callDigitalPayoff = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (callDigitalPayoff) ? (QuantLib::Rate)ValueHelper::Convert (callDigitalPayoff->Value) : Null<QuantLib::Rate>()); //4
        QuantLib::Rate _putStrike = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (putStrike) ? (QuantLib::Rate)ValueHelper::Convert (putStrike->Value) : Null<QuantLib::Rate>()); //4
        QuantLib::Position::Type _putPosition = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Position::TypeEnum>::IsSome::get (putPosition) ? (QuantLib::Position::Type)putPosition->Value : QuantLib::Position::Type::Long); //10
        bool _isPutITMIncluded = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isPutITMIncluded) ? (bool)ValueHelper::Convert (isPutITMIncluded->Value) : false); //4
        QuantLib::Rate _putDigitalPayoff = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (putDigitalPayoff) ? (QuantLib::Rate)ValueHelper::Convert (putDigitalPayoff->Value) : Null<QuantLib::Rate>()); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Cashflows::IDigitalReplication^>::IsSome::get (replication))
        {
            _Creplication = safe_cast<CDigitalReplication^> (replication->Value);
            _Creplication->Lock();
        }
        boost::shared_ptr<QuantLib::DigitalReplication>& _replication = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Cashflows::IDigitalReplication^>::IsSome::get (replication) ? static_cast<boost::shared_ptr<QuantLib::DigitalReplication>&> (_Creplication->GetShared ()) : boost::shared_ptr<QuantLib::DigitalReplication>()); //1
        _ppDigitalCoupon = new boost::shared_ptr<QuantLib::DigitalCoupon> (new QuantLib::DigitalCoupon ( _underlying,  _callStrike,  _callPosition,  _isCallITMIncluded,  _callDigitalPayoff,  _putStrike,  _putPosition,  _isPutITMIncluded,  _putDigitalPayoff,  _replication ));
        CFloatingRateCouponPricer^ _CQL_Pricer = safe_cast<CFloatingRateCouponPricer^> (QL_Pricer);
        boost::shared_ptr<QuantLib::FloatingRateCouponPricer>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::FloatingRateCouponPricer>&> (_CQL_Pricer->GetShared ());
        (*_ppDigitalCoupon)->setPricer (_QL_Pricer);
        SetFloatingRateCoupon (boost::dynamic_pointer_cast<QuantLib::FloatingRateCoupon> (*_ppDigitalCoupon));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cunderlying != nullptr) _Cunderlying->Unlock();
        if (_Creplication != nullptr) _Creplication->Unlock();
    }
}
Cephei::QL::Cashflows::CDigitalCoupon::CDigitalCoupon (boost::shared_ptr<QuantLib::DigitalCoupon>& childNative, Object^ owner) : CFloatingRateCoupon(CDigitalCoupon::typeid)
{
#ifdef HANDLE
	_phDigitalCoupon = NULL;
#endif
	_ppDigitalCoupon = &childNative;
    _ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (boost::dynamic_pointer_cast<QuantLib::FloatingRateCoupon> (*_ppDigitalCoupon));
}
Cephei::QL::Cashflows::CDigitalCoupon::CDigitalCoupon (QuantLib::DigitalCoupon& childNative, Object^ owner) : CFloatingRateCoupon(CDigitalCoupon::typeid)
{
#ifdef HANDLE
	_phDigitalCoupon = NULL;
#endif
	_ppDigitalCoupon = new boost::shared_ptr<QuantLib::DigitalCoupon> (&childNative);
    _ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (boost::dynamic_pointer_cast<QuantLib::FloatingRateCoupon> (*_ppDigitalCoupon));
    _DigitalCouponOwner = owner;
    _FloatingRateCouponOwner = owner;
}

Cephei::QL::Cashflows::CDigitalCoupon::CDigitalCoupon (CDigitalCoupon^ copy) : CFloatingRateCoupon(CDigitalCoupon::typeid)
{
#ifdef HANDLE
	_phDigitalCoupon = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppDigitalCoupon = new boost::shared_ptr<QuantLib::DigitalCoupon> (copy->GetShared());
        _ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (boost::dynamic_pointer_cast<QuantLib::FloatingRateCoupon> (*_ppDigitalCoupon));
    }
}
Cephei::QL::Cashflows::CDigitalCoupon::CDigitalCoupon (System::Type^ t) : CFloatingRateCoupon(CDigitalCoupon::typeid)
{
#ifdef HANDLE
	_phDigitalCoupon = NULL;
#endif
	if (!t->IsSubclassOf(CDigitalCoupon::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Cashflows::CDigitalCoupon::CDigitalCoupon (QuantLib::Handle<QuantLib::DigitalCoupon>& childNative, Object^ owner)  : CFloatingRateCoupon(CDigitalCoupon::typeid)
{
	_phDigitalCoupon = &childNative;
	_ppDigitalCoupon = &static_cast<boost::shared_ptr<QuantLib::DigitalCoupon>>(childNative.currentLink());
    _ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (boost::dynamic_pointer_cast<QuantLib::FloatingRateCoupon> (*_ppDigitalCoupon));
    _DigitalCouponOwner = owner;
}
Cephei::QL::Cashflows::CDigitalCoupon::CDigitalCoupon (QuantLib::Handle<QuantLib::DigitalCoupon> childNative)  : CFloatingRateCoupon(CDigitalCoupon::typeid)
{
	_phDigitalCoupon = &childNative;
	_ppDigitalCoupon = &static_cast<boost::shared_ptr<QuantLib::DigitalCoupon>>(childNative.currentLink());
    _ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (boost::dynamic_pointer_cast<QuantLib::FloatingRateCoupon> (*_ppDigitalCoupon));
}
#endif
#ifdef STRUCT
Cephei::QL::Cashflows::CDigitalCoupon::CDigitalCoupon (QuantLib::DigitalCoupon childNative)  : CFloatingRateCoupon(CDigitalCoupon::typeid)
{
#ifdef HANDLE
	_phDigitalCoupon = NULL;
#endif
	_ppDigitalCoupon = new boost::shared_ptr<QuantLib::DigitalCoupon> (new QuantLib::DigitalCoupon (childNative));
    _ppFloatingRateCoupon = new boost::shared_ptr<QuantLib::FloatingRateCoupon> (boost::dynamic_pointer_cast<QuantLib::FloatingRateCoupon> (*_ppDigitalCoupon));
}
#endif

Cephei::QL::Cashflows::CDigitalCoupon::~CDigitalCoupon ()
{
    if (_ppDigitalCoupon != NULL)
    {
	    delete _ppDigitalCoupon;
        _ppDigitalCoupon = NULL;
    }
}
Cephei::QL::Cashflows::CDigitalCoupon::!CDigitalCoupon ()
{
    if (_ppDigitalCoupon != NULL)
    {
	    delete _ppDigitalCoupon;
    }
}
QuantLib::DigitalCoupon& Cephei::QL::Cashflows::CDigitalCoupon::GetReference ()
{
    if (_ppDigitalCoupon == NULL) throw gcnew NativeNullException ();
	return **_ppDigitalCoupon;
}
boost::shared_ptr<QuantLib::DigitalCoupon>& Cephei::QL::Cashflows::CDigitalCoupon::GetShared ()
{
    if (_ppDigitalCoupon == NULL) throw gcnew NativeNullException ();
	return *_ppDigitalCoupon;
}
QuantLib::DigitalCoupon* Cephei::QL::Cashflows::CDigitalCoupon::GetPointer ()
{
    if (_ppDigitalCoupon == NULL) throw gcnew NativeNullException ();
	return &**_ppDigitalCoupon;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::DigitalCoupon>& Cephei::QL::Cashflows::CDigitalCoupon::GetHandle ()
{
	if (_phDigitalCoupon == NULL)
	{
		_phDigitalCoupon = new Handle<QuantLib::DigitalCoupon> (*_ppDigitalCoupon);
	}
	return *_phDigitalCoupon;
}
#endif
bool Cephei::QL::Cashflows::CDigitalCoupon::HasNative () 
{
	return (_ppDigitalCoupon != NULL);
}

Double Cephei::QL::Cashflows::CDigitalCoupon::CallDigitalPayoff::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDigitalCoupon)->callDigitalPayoff ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CDigitalCoupon::CallOptionRate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDigitalCoupon)->callOptionRate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CDigitalCoupon::CallStrike::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDigitalCoupon)->callStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CDigitalCoupon::ConvexityAdjustment::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDigitalCoupon)->convexityAdjustment ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Cashflows::CDigitalCoupon::HasCall::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppDigitalCoupon)->hasCall ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Cashflows::CDigitalCoupon::HasCollar::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppDigitalCoupon)->hasCollar ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Cashflows::CDigitalCoupon::HasPut::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppDigitalCoupon)->hasPut ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Cashflows::CDigitalCoupon::IsLongCall::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppDigitalCoupon)->isLongCall ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Cashflows::CDigitalCoupon::IsLongPut::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppDigitalCoupon)->isLongPut ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CDigitalCoupon::PutDigitalPayoff::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDigitalCoupon)->putDigitalPayoff ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CDigitalCoupon::PutOptionRate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDigitalCoupon)->putOptionRate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CDigitalCoupon::PutStrike::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDigitalCoupon)->putStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CDigitalCoupon::Rate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDigitalCoupon)->rate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Cashflows::IDigitalCoupon^ Cephei::QL::Cashflows::CDigitalCoupon::SetPricer (Cephei::QL::Cashflows::IFloatingRateCouponPricer^ pricer)
{
    CFloatingRateCouponPricer^ _Cpricer;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cpricer = safe_cast<CFloatingRateCouponPricer^> (pricer);
        _Cpricer->Lock();
        boost::shared_ptr<QuantLib::FloatingRateCouponPricer>& _pricer = static_cast<boost::shared_ptr<QuantLib::FloatingRateCouponPricer>&> (_Cpricer->GetShared ()); 
    	(*_ppDigitalCoupon)->setPricer ( _pricer );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cpricer != nullptr) _Cpricer->Unlock();
    }
}
Cephei::QL::Cashflows::IFloatingRateCoupon^ Cephei::QL::Cashflows::CDigitalCoupon::Underlying::get ()
{
    try
    {
    	boost::shared_ptr<QuantLib::FloatingRateCoupon> _rv = (boost::shared_ptr<QuantLib::FloatingRateCoupon>)(*_ppDigitalCoupon)->underlying ( );   
        Cephei::QL::Cashflows::CFloatingRateCoupon^ _nrv = gcnew Cephei::QL::Cashflows::CFloatingRateCoupon (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Cashflows::IDigitalCoupon^ Cephei::QL::Cashflows::CDigitalCoupon::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppDigitalCoupon)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Cashflows::IDigitalCoupon^ Cephei::QL::Cashflows::CDigitalCoupon_Factory::Create (Cephei::QL::Cashflows::IFloatingRateCoupon^ underlying, Microsoft::FSharp::Core::FSharpOption<Double>^ callStrike, Microsoft::FSharp::Core::FSharpOption<QL::Position::TypeEnum>^ callPosition, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isCallITMIncluded, Microsoft::FSharp::Core::FSharpOption<Double>^ callDigitalPayoff, Microsoft::FSharp::Core::FSharpOption<Double>^ putStrike, Microsoft::FSharp::Core::FSharpOption<QL::Position::TypeEnum>^ putPosition, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isPutITMIncluded, Microsoft::FSharp::Core::FSharpOption<Double>^ putDigitalPayoff, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Cashflows::IDigitalReplication^>^ replication, Cephei::QL::Cashflows::IFloatingRateCouponPricer^ QL_Pricer)
{
    return gcnew CDigitalCoupon ( underlying,  callStrike,  callPosition,  isCallITMIncluded,  callDigitalPayoff,  putStrike,  putPosition,  isPutITMIncluded,  putDigitalPayoff,  replication,  QL_Pricer);
}
